package com.itheima.collectionDemo;

import java.util.ArrayList;
import java.util.Collection;

public class CollectionDemo2 {
    public static void main(String[] args) {
        Collection<String> collection = new ArrayList<>();
        collection.add("aaa");
        collection.add("bbb");
        collection.add("ccc");
        collection.add("dddd");
        System.out.println(collection);

//        method1(collection);
//        method2(collection);
//        method3(collection);
//        method4(collection);
//        method5(collection);
//        method6(collection);
    }

    private static void method6(Collection<String> collection) {
        int size = collection.size();
        System.out.println(size);
    }

    private static void method5(Collection<String> collection) {
        collection.clear();
        boolean result = collection.isEmpty();
        System.out.println(result);
    }


    private static void method4(Collection<String> collection) {
        boolean result = collection.contains("a");
        System.out.println(result);
        boolean result2 = collection.contains("aaa");
        System.out.println(result2);
    }

    private static void method3(Collection<String> collection) {
        collection.clear();
        System.out.println(collection);
    }

    private static void method2(Collection<String> collection) {
//        boolean test(T t);
        // removeif 方法底层会遍历集合，得到集合中的每一个元素
        // s 依次表示集合中的每一个元素
        // 就会把这每一个元素都到lamda表达式中去判定一下
        // 如果返回ture,则删除
        // 如果返回 false，则保留不删除
        collection.removeIf((String s) -> {return s.length() == 3;});
        System.out.println(collection);
    }

    private static void method1(Collection<String> collection) {
        boolean resultA = collection.remove("aaa");
        boolean resultB = collection.remove("ddd");
        System.out.println(resultA);
        System.out.println(resultB);
        System.out.println(collection);
    }
}
